/*
 * Copyright (c) 2008, Xiong Yingfei, the University of Tokyo
 * All rights reserved.
 */
package ac.jp.u_tokyo.SyncLib;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class HandleArgNumberAspect {
	
	@Before("execution(* Sync.resynchronize(..)) && args(values, modifications) && target(sync)")
	public void checkResyncNumber(Object[] values, Mod[] modifications, Sync sync) throws SynchronizationFailedException {
		if (values.length != sync.getParaCount())
			throw new SynchronizationFailedException("The number of arguments is not correct.");
		checkSyncNumber(modifications, sync);
	}
	
	@Before("execution(* Sync.synchronize(..)) && args(modifications) && target(sync)")
	public void checkSyncNumber(Mod[] modifications, Sync sync) throws SynchronizationFailedException {
		if (modifications.length != sync.getParaCount()) {
			throw new SynchronizationFailedException("The number of arguments is not correct.");
		}
		for (int i = 0; i < modifications.length; i++) {
			if (modifications[i] == null)
				throw new SynchronizationFailedException("An update cannot be null.");
		}
	}

}
